<?php

// get news item
	$d = ($edit) ? $module->news_get($edit) : false;
	$c = ($edit) ? $module->getCats($edit['id']) : array($module->getDefaultCat());

// default category
	$cIds = array();
	foreach($c as $k => $v) $cIds[] = $v['id'];

// get all categories
	$cats = $module->getCats();

// title
	?><h1 class="<?php echo ($add) ? 'add' : 'edit'; ?>"><?php echo ($add) ? $lang->get('add-news') : $lang->get('edit-news'); ?></h1><?php

// form
	if(count($cats)) {
		?>
		<form name="frm" method="post" action="<?php echo $cosa->system('base-url'); ?>/?m=<?php echo $m; ?>&s=<?php echo $s; ?>">
		<input type="hidden" name="<?php echo ($add) ? 'add' : 'edit'; ?>" value="<?php echo ($add) ? '1' : $d['id']; ?>" />
		<?php if(count($cats) == 1) { ?><input type="hidden" name="cat_<?php echo $cats[0]['id']; ?>" value="1" /><?php } ?>
		<ul>
			<li><label for="title"><?php $lang->put('title'); ?></label>
				<input type="text" name="title" value="<?php if($d) echo stripslashes($d['title']); ?>" class="fld" />
			</li>
			<li><label for="title"><?php $lang->put('text'); ?></label>
				<textarea name="text" id="text"><?php if($d) echo stripslashes($d['text']); ?></textarea>
			</li>
			<?php if(count($cats) > 1) { ?>
			<li><label for="cat"><?php $lang->put('cat'); ?></label>
				<ul>
					<?php
					foreach($cats as $k => $cat) {
						$checked = (in_array($cat['id'], $cIds)) ? ' checked="checked"' : '';
						echo '<li>';
						echo '<input type="checkbox" name="cat_'.$cat['id'].'" id="cat_'.$cat['id'].'" value="1"'.$checked.' class="cbx" />';
						echo '<label for="cat_'.$cat['id'].'">'.stripslashes($cat['title']).'</label>';
						echo '</li>'."\n";
					}
					?>
				</ul>
			</li>
			<?php } ?>
			<li class="sbmt">
				<input type="submit" value="<?php $lang->put('submit'); ?>" class="sbmt" />
				<?php if($d) $module->printDelLink($d['id'], false, $lang->get('del-news')); ?>
			</li>
		</ul>
		</form>
		<?php
	
	} else {
		
		$url = $cosa->system('base-url').'/?m='.$m.'&s=cat&add';
		echo sprintf($lang->get('news-cat-noneset'), $url);
		
	}

?>